using System;
using System.Data;
using System.Web;
using System.Collections;
using System.Collections.Generic;
using System.Web.Services;
using System.Web.Services.Protocols;
using System.ComponentModel;
using System.Data.SqlClient;

namespace DbService
{
   /// <summary>
   /// Summary description for KlantenInfo
   /// </summary>
   [WebService(Namespace = "http://localhost/")]
   [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
   [ToolboxItem(false)]
   public class KlantenInfo : System.Web.Services.WebService
   {

      [WebMethod]
      public Klant GetKlantInfo(string email)
      {
         SqlConnection sqlConn = null;
         SqlDataReader sqlRdr = null;
         Klant klant = null;
         try
         {
            sqlConn = new SqlConnection(Global.GetConnectionString());
            sqlConn.Open();

            SqlCommand sqlcmdValidateLogin = new SqlCommand("sp_klantenInfo", sqlConn);
            sqlcmdValidateLogin.CommandType = CommandType.StoredProcedure;

            sqlcmdValidateLogin.Parameters.Add(new SqlParameter("email", email));

            sqlRdr = sqlcmdValidateLogin.ExecuteReader();

            Dictionary<string, string> dataResult = new Dictionary<string,string>();
            
            // Call Read before accessing data.
            while (sqlRdr.Read())
            {
                klant = new Klant();
            //   dataResult.Add(String.Format("{0}", sqlRdr[0]), String.Format("{1}", sqlRdr[1]));
                klant.Email = sqlRdr["Email"].ToString();
                klant.Firstname = sqlRdr["Voornaam"].ToString();
                klant.Lastname = sqlRdr["Achternaam"].ToString();
                klant.Name_addition = sqlRdr["Tussenvoegsel"].ToString();
                klant.Address = sqlRdr["Adres"].ToString();
                klant.House_number = Int32.Parse(sqlRdr["Huisnummer"].ToString());
                klant.House_number_add = sqlRdr["Huisnummertoevoeging"].ToString();
                klant.City = sqlRdr["Woonplaats"].ToString();
                klant.Postal_code = sqlRdr["Postcode"].ToString();
                klant.Member_number = Int32.Parse(sqlRdr["Abonneenummer"].ToString());
            } 
            // Call Close when done reading.
            sqlRdr.Close();          
         }
         catch (SqlException ex)
         {
             Global.WriteDebugLine(ex.ToString());
         }
         finally
         {
            if (null != sqlRdr)
            {
               sqlRdr.Close();
            }

            if (null != sqlConn)
            {
               sqlConn.Close();
            }
            
         }
         return klant;
      }
   }
}
